import { Entity, Column, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { ApiProperty} from '@nestjs/swagger';
import { IsOptional, IsDefined } from 'class-validator';
import { Order } from './order.entities';
import { Goods } from './goods.entity';
import { Product } from './product.entities';

@Entity()
export class OrderGoods {
  @PrimaryGeneratedColumn({type: 'mediumint'})
  id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'mediumint'})
  order_id:number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'mediumint'})
  goods_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 120 })
  goods_name: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 60, comment: "商品序列号"})
  goods_sn: string;

  @IsOptional()
  @IsDefined()
  @ApiProperty()
  @Column({type: 'mediumint'})
  product_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'smallint', comment: "商品数量"})
  number: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', precision: 2, width: 10, comment: "市场价"})
  market_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', precision: 2, width: 10, comment: "零售价格"})
  retail_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'text', comment: "商品规格详情"})
  goods_specifition_name_value: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', comment: "虚拟商品"})
  is_real: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255, comment: "商品规格Ids"})
  goods_specifition_ids: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255, comment: "图片链接"})
  list_pic_url: string;

  @IsOptional()
  @ApiProperty({type: ()=>Order})
  @ManyToOne(type => Order,order => order.orderGoods)
  @JoinColumn({
    name:'order_id'
  })
  order:Order

  @ManyToOne(type => Goods,goods => goods.orderGoods)
  @JoinColumn({
    name:'goods_id'
  })
  goods:Goods

  @ManyToOne(type => Product,product => product.orderGoods)
  @JoinColumn({
    name:'product_id'
  })
  product:Product
}
